#!/usr/bin/env node
const path = require("path");
const program = require("commander");
const { normalizePath, load } = require("./utils");
const { compileIndexTemplate } = require("./compile");
// const React = require("react");
// const ReactDOM = require("react-dom");

program
  .version("0.1.0")
  .option(
    "-C, --config <path>",
    "azirbook config path",
    path.resolve(process.cwd(), "./azirbook.config.js")
  );
program.parse(process.argv);

if (program.config) {
  const configPath = path.resolve(process.cwd(), program.config);
  const configDir = path.dirname(configPath);
  const { root, indexTemplate, nav } = load(configPath);
  const rootPath = normalizePath(configDir, root);
  const indexTemplatePath = normalizePath(configDir, indexTemplate);
  if (indexTemplatePath) {
    compileIndexTemplate(indexTemplatePath);
  }
  // const tmpCode = fs.readFileSync(
  //   normalizePath(configDir, indexTemplate),
  //   "utf-8"
  // );
  // console.log(rootPath, tmpCode);
}
